﻿@model ToyStore.Web.Mvc.Controllers.ViewModels.ProductListViewModel
@using PagedList.Mvc;
@using PagedList; 
@using ToyStore.Domain.Store;
@{
    ViewBag.Title = "Lista produktów";
    Layout = "~/Views/Shared/_Layout.cshtml";
    
    
    
}


<script type="text/javascript" language="javascript">
    $().ready(function () {
        $('.PagedList-skipToPrevious a').text("Poprzednia");
        $('.PagedList-skipToNext a').text("Następna");
        $(".flipbox").find(".addToCart a").on("click", function (event) { //add to chart
            event.preventDefault();
            var link = $(this);
            var productId = link.data("id");
            ShowAjaxLoader();
            $.ajax({
                type: 'POST',
                url: '@Url.Action("AddProductAjax", "Cart")',
                data: { id: productId },
                success: function (data) {
                    if (data != undefined) {
                        link.closest(".flipbox").find(".ribbon").hide().addClass("ribbon_in_cart").fadeIn();
                        link.fadeOut();
                        var result = $("#basketTemplate").tmpl(data);
                        $("#basket").html(result);
                        HideAjaxLoader();
                    }
                }
            });
        });

        $("#SortType").change(function () { $('#sortForm').submit(); });
        $("#ItemsOnPage").change(function () { $('#sortForm').submit(); });
    });

</script>
<script id="basketTemplate" type="text/x-jquery-tmpl">
    <div id="basket-ico">
	</div>
	<div id="basket-info">
		w koszyku : ${amount} szt (${sum} zł)
		<br />
		@(Html.ActionLink<CartController>(c => c.Index(), "przejdź do koszyka"))
	</div>
</script>

@using (Html.BeginForm("GetProductsByCategory", "Product", FormMethod.Get, new { @id = "sortForm"}))
{
 @:Wybierz sposób sortowania @Html.DropDownList("SortType", new SelectList(Model.SortTypes, "Value", "Text"), "Brak", new { style = "width:175px"})
 @:Pokaż @Html.DropDownList("ItemsOnPage", new SelectList(Model.ItemsOnPageList, "Value", "Text"), new { style = "width:60px" })
 @Html.HiddenFor(c => c.CategoryId);
}

@if (Model.ProductsList.TotalItemCount > Model.ItemsOnPage)
{
@:<div class="pull-left">@Html.PagedListPager(Model.ProductsList, x => Url.Action("GetProductsByCategory", "Product", new { categoryId = Model.CategoryId, pageNumber = x, itemsOnPage = Model.ItemsOnPage, sortType = Model.SelectedSortType }))</div>
@:<div style="clear:both"></div>
}
@foreach (Product p in (System.Collections.IEnumerable)Model.ProductsList)
{
  @Html.Partial("_ProductListTemplate", new ToyStore.Web.Mvc.Controllers.ViewModels.ProductListTemplateViewModel { Product = p, ProductsInUserCard = Model.ProductsInUserCard })
}
<div style="clear:both"></div>
@if (Model.ProductsList.TotalItemCount > Model.ItemsOnPage)
{
@:<div style="clear:both"></div>
@:<div class="pull-left">@Html.PagedListPager(Model.ProductsList, x => Url.Action("GetProductsByCategory", "Product", new { categoryId = Model.CategoryId, pageNumber = x, itemsOnPage = Model.ItemsOnPage, sortType = Model.SelectedSortType }))</div>
}
 <script src="@Url.Content("/Scripts/jquery.flip.js")" type="text/javascript"></script>
 <script src="@Url.Content("/Scripts/productListTemplates.js")" type="text/javascript"></script>